home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / littelcomp / r5 / lc / lc17.e < prev    next >
Text File  |  2000-02-28  |  9KB  |  282 lines

  1. -> Example 'Straight off' Compilator for littel_a68k.library (R5)
  2. -> AUTHOR : leif_salomonsson@swipnet.se
  3. -> STATUS : FREEWARE
  4.  
  5. MODULE 'dos/dos'
  6. MODULE '*extractwords'
  7. MODULE '*littel_a68k'
  8. MODULE 'utility'
  9.  
  10.  
  11.    DEF mem:PTR TO CHAR
  12.    DEF ew:PTR TO extractwords
  13.    DEF linenum=1
  14.  
  15. RAISE "OPEN" IF Open() = NIL,
  16.       "LIB" IF OpenLibrary() = NIL
  17.  
  18. PROC main() HANDLE
  19.    DEF withext[100]:STRING
  20.    DEF len
  21.    DEF fh=NIL
  22.    DEF rlen
  23.    DEF ostr[100]:STRING
  24.    StringF(withext, '\s.l', arg)
  25.    NEW ew.new(20, 500)
  26.    littel_a68kbase := OpenLibrary('littel_a68k.library', 5)
  27.    utilitybase := OpenLibrary('utility.library', 37)
  28.    len := FileLength(withext)
  29.    mem := New(len)
  30.    fh := Open(withext, MODE_OLDFILE)
  31.    rlen := Read(fh, mem, len)
  32.    IF rlen <> len THEN Raise("READ")
  33.    Lit_Start(arg)
  34.    WriteF(' Compiler Example For LITTEL v0.17b © Leif Salomonsson -99\n')
  35.    WriteF('     Parsing and Compiling : \s\n', withext)
  36.    do_commands()
  37.    Lit_End()
  38.    WriteF('\b     Assembling\n')
  39.    Lit_Ass()
  40.    WriteF('     Linking\n')
  41.    Lit_Lnk()
  42.    WriteF('     Finnished ')
  43.    IF StrCmp(Lit_GetModeStr(), 'EXE')
  44.       WriteF('EXE')
  45.       WriteF(' \s : \d bytes!\n', arg, FileLength(arg))
  46.    ELSEIF StrCmp(Lit_GetModeStr(), 'LIBRARY')
  47.       WriteF('LIBRARY')
  48.       WriteF(' \s : \d bytes!\n', arg, FileLength(arg))
  49.    ELSEIF StrCmp(Lit_GetModeStr(), 'OBJECT')
  50.       StringF(ostr, '\s.o', arg)
  51.       WriteF('OBJECT')
  52.       WriteF(' \s : \d bytes!\n', ostr, FileLength(ostr))
  53.    ENDIF
  54. EXCEPT DO
  55. SELECT exception
  56. CASE "^C" ; WriteF('ctrl c break!\n')
  57. CASE "OPEN" ; WriteF('open error!\n')
  58. CASE "READ" ; WriteF('read error!\n')
  59. CASE "LIB"
  60. ENDSELECT
  61.    IF fh THEN Close(fh)
  62.    IF littel_a68kbase
  63.       CloseLibrary(littel_a68kbase)
  64.    ENDIF
  65.    IF utilitybase THEN CloseLibrary(utilitybase)
  66. ENDPROC
  67.  
  68. PROC do_commands()
  69.    DEF str
  70.    DEF arg1, arg2, arg3, arg4, arg5, array
  71.    mem := nextLine(mem)
  72.    LOOP
  73.       IF CtrlC() THEN Raise("^C")
  74.  
  75.          WriteF('\b\d[4]', linenum)
  76.  
  77.          ew.extract(mem)
  78.          str := ew.getWord(0) ; arg1 := ew.getWord(1)
  79.          arg2 := ew.getWord(2) ; arg3 := ew.getWord(3)
  80.          arg4 := ew.getWord(4) ; arg5 := ew.getWord(5)
  81.          array := ew.getArray() + 4
  82.  
  83.          IF str = NIL
  84.             ->
  85.      
  86.          ELSEIF Stricmp(str, 'CODESTART')=NIL
  87.             Lkw_Codestart()
  88.          ELSEIF Stricmp(str, 'copy')=NIL
  89.             Lis_Copy(arg1, arg2)
  90.          ELSEIF Stricmp(str, 'WHILE')=NIL
  91.             Lkw_WHILE(arg1, arg2, arg3)
  92.          ELSEIF Stricmp(str, 'VAR')=NIL
  93.             Lkw_Var(array)
  94.          ELSEIF Stricmp(str, 'inc')=NIL
  95.             Lis_Inc(arg1, arg2)
  96.          ELSEIF Stricmp(str, 'dec')=NIL
  97.             Lis_Dec(arg1, arg2)
  98.          ELSEIF Stricmp(str, 'add')=NIL
  99.             Lis_Add(arg1, arg2, arg3)
  100.          ELSEIF Stricmp(str, 'sub')=NIL
  101.             Lis_Sub(arg1, arg2, arg3)
  102.          ELSEIF Stricmp(str, 'ENDSELECT')=NIL
  103.             Lkw_ENDSELECT()
  104.          ELSEIF Stricmp(str, 'ENDREPEAT')=NIL
  105.             Lkw_ENDREPEAT(arg1, arg2, arg3)
  106.          ELSEIF Stricmp(str, 'ENDWHILE')=NIL
  107.             Lkw_ENDWHILE()
  108.          ELSEIF Stricmp(str, 'ENDPROC')=NIL
  109.             Lkw_Endproc(array)
  110.          ELSEIF Stricmp(str, 'ENDIF')=NIL
  111.             Lkw_ENDIF()
  112.          ELSEIF Stricmp(str, 'END')=NIL
  113.             RETURN
  114.          ELSEIF Stricmp(str, 'REPEAT')=NIL
  115.             Lkw_REPEAT()
  116.          ELSEIF Stricmp(str, 'IF')=NIL
  117.             Lkw_IF(arg1, arg2, arg3)
  118.          ELSEIF Stricmp(str, 'SELECT')=NIL
  119.             Lkw_SELECT(arg1)
  120.          ELSEIF Stricmp(str, 'CASE')=NIL
  121.             Lkw_CASE(arg1, arg2, arg3)
  122.          ELSEIF Stricmp(str, 'Rtos')=NIL
  123.             Lis_Rtos(arg1)
  124.          ELSEIF Stricmp(str, 'Stor')=NIL
  125.             Lis_Stor(arg1)
  126.          ELSEIF Stricmp(str, 'padr')=NIL
  127.             Lis_Padr(arg1, arg2)
  128.          ELSEIF Stricmp(str, 'LONGS')=NIL
  129.             Lkw_Longs(arg1, arg2)
  130.          ELSEIF Stricmp(str, 'WORDS')=NIL
  131.             Lkw_Words(arg1, arg2)
  132.          ELSEIF Stricmp(str, 'BYTES')=NIL
  133.             Lkw_Bytes(arg1, arg2)
  134.          ELSEIF Stricmp(str, 'LBLK')=NIL
  135.             Lkw_Lblk(arg1, arg2)
  136.          ELSEIF Stricmp(str, 'WBLK')=NIL
  137.             Lkw_Wblk(arg1, arg2)
  138.          ELSEIF Stricmp(str, 'BBLK')=NIL
  139.             Lkw_Bblk(arg1, arg2)
  140.          ELSEIF Stricmp(str, 'PROC')=NIL
  141.             Lkw_Proc(arg1, array)
  142.          ELSEIF Stricmp(str, 'dpr')=NIL
  143.             Lis_Dpr(arg1, array)
  144.          ELSEIF Stricmp(str, 'cdpr')=NIL
  145.             Lis_Dpr(arg1, array)
  146.             Lis_Check()
  147.          ELSEIF Stricmp(str, 'call')=NIL
  148.             Lis_Call(arg1, arg2)
  149.          ELSEIF Stricmp(str, 'ccall')=NIL
  150.             Lis_Call(arg1, arg2)
  151.             Lis_Check()
  152.          ELSEIF Stricmp(str, 'shl')=NIL
  153.             Lis_Shl(arg1, arg2, arg3)
  154.          ELSEIF Stricmp(str, 'shr')=NIL
  155.             Lis_Shr(arg1, arg2, arg3)
  156.          ELSEIF Stricmp(str, 'div')=NIL
  157.             Lis_Div(arg1, arg2, arg3)
  158.          ELSEIF Stricmp(str, 'mul')=NIL
  159.             Lis_Mul(arg1, arg2, arg3)
  160.          ELSEIF Stricmp(str, '#incdir')=NIL
  161.             Lck_Incdir(arg1)
  162.          ->ELSEIF Stricmp(str, '#linkdir')=NIL
  163.          ->   do_linkdir(arg1)
  164.          ELSEIF Stricmp(str, '#include')=NIL
  165.             Lck_mInclude(array)
  166.          ELSEIF Stricmp(str, '#equ')=NIL
  167.             Lck_Const(arg1, arg2)
  168.          ELSEIF Stricmp(str, '#mode')=NIL
  169.             Lck_Mode(arg1, arg2, arg3, arg4, arg5)
  170.          ELSEIF Stricmp(str, '#link')=NIL
  171.             Lck_mLink(array)
  172.          ELSEIF Stricmp(str, '#xdef')=NIL
  173.             Lck_mXdef(array)
  174.          ELSEIF Stricmp(str, '#xref')=NIL
  175.             Lck_mXref(array)
  176.          ELSEIF Stricmp(str, 'STRING')=NIL
  177.             Lkw_String(arg1, arg2)
  178.          ELSEIF Stricmp(str, 'GVAR')=NIL
  179.             Lkw_Gvar(array)
  180.          ELSEIF Stricmp(str, 'swap')=NIL
  181.             Lis_Swap(arg1, arg2)
  182.          ELSEIF Stricmp(str, 'ELSE')=NIL
  183.             Lkw_ELSE()
  184.          ELSEIF Stricmp(str, 'DEFAULT')=NIL
  185.             Lkw_DEFAULT()
  186.          ELSEIF Stricmp(str, 'and')=NIL
  187.             Lis_And(arg1, arg2, arg3)
  188.          ELSEIF Stricmp(str, 'or')=NIL
  189.             Lis_Or(arg1, arg2, arg3)
  190.          ELSEIF Stricmp(str, 'not')=NIL
  191.             Lis_Not(arg1, arg2)
  192.          ELSEIF Stricmp(str, 'xor')=NIL
  193.             Lis_Xor(arg1, arg2, arg3)
  194.          ELSEIF Stricmp(str, 'bset')=NIL
  195.             Lis_Bset(arg1, arg2, arg3)
  196.          ELSEIF Stricmp(str, 'bclr')=NIL
  197.             Lis_Bclr(arg1, arg2, arg3)
  198.          ELSEIF Stricmp(str, 'bget')=NIL
  199.             Lis_Bget(arg1, arg2, arg3)
  200.          ELSEIF Stricmp(str, 'bchg')=NIL
  201.             Lis_Bchg(arg1, arg2, arg3)
  202.          ELSEIF Stricmp(str, 'neg')=NIL
  203.             Lis_Neg(arg1, arg2)
  204.          ELSEIF Stricmp(str, 'lmt')=NIL
  205.             Lis_Lmt(arg1, arg2, arg3)
  206.          ELSEIF Stricmp(str, 'max')=NIL
  207.             Lis_Max(arg1, arg2, arg3)
  208.          ELSEIF Stricmp(str, 'min')=NIL
  209.             Lis_Min(arg1, arg2, arg3)
  210.          ELSEIF Stricmp(str, 'abs')=NIL
  211.             Lis_Abs(arg1, arg2)
  212.          ELSEIF Stricmp(str, 'ret')=NIL
  213.             Lis_Ret(array)
  214.          ELSEIF Stricmp(str, 'CONT')=NIL
  215.             Lkw_CONT(arg1, arg2, arg3)
  216.          ELSEIF Stricmp(str, 'geta4')=NIL
  217.             Lis_Geta4()
  218.          ELSEIF Stricmp(str, 'rems')=NIL
  219.             Lis_Rems(arg1)
  220.          ELSEIF Stricmp(str, 'Push')=NIL
  221.             Lis_Push(array)
  222.          ELSEIF Stricmp(str, 'Pop')=NIL
  223.             Lis_Pop(array)
  224.          ELSEIF Stricmp(str, '#fdef')=NIL
  225.             Lib_Fdef(arg1, arg2)
  226.          ELSEIF Stricmp(str, '#endfdef')=NIL
  227.             Lib_EndFdef()
  228.          ELSEIF Stricmp(str, '#makefd')=NIL
  229.             Lib_MakeFD(arg1, arg2)
  230.          ELSEIF Stricmp(str, '#makei')=NIL
  231.             Lib_MakeI(arg1)
  232.          ELSEIF Stricmp(str, '#makelvo')=NIL
  233.             Lib_MakeLVO(arg1)
  234.          ELSEIF Stricmp(str, 'raise')=NIL
  235.             Lis_Raise(arg1, arg2, arg3, arg4, arg5)
  236.          ELSEIF Stricmp(str, 'check')=NIL
  237.             Lis_Check()
  238.          ELSEIF Stricmp(str, 'throw')=NIL
  239.             Lis_Throw(arg1, arg2)
  240.          ELSEIF Stricmp(str, 'rthrw')=NIL
  241.             Lis_Rthrw()
  242.          ELSEIF Stricmp(str, 'EXCEPT')=NIL
  243.             Lkw_Except(arg1)
  244.          ELSEIF Stricmp(str, 'dmf')=NIL
  245.             Lis_Dmf(arg1, array)
  246.          ELSEIF Stricmp(str, 'LOOP')=NIL
  247.             Lis_LOOP(arg1)
  248.          ELSEIF Stricmp(str, 'ENDLOOP')=NIL
  249.             Lis_ENDLOOP()
  250.          ELSEIF Stricmp(str, 'FOR')=NIL
  251.             Lis_FOR(arg1, arg2, arg3, arg4)
  252.          ELSEIF Stricmp(str, 'ENDFOR')=NIL
  253.             Lis_ENDFOR()
  254.          ELSEIF Stricmp(str, 'CND')=NIL
  255.             Lis_Cnd(arg1, arg2, arg3, arg4)
  256.          ELSEIF Stricmp(str, 'Lab')=NIL
  257.             Lis_Lab(arg1)
  258.          ELSEIF Stricmp(str, 'BIC')=NIL
  259.             Lis_Bic(arg1, arg2, arg3, arg4)
  260.          ELSEIF Stricmp(str, '#LibraryEnv')=NIL
  261.             Lib_LibraryEnv(arg1)
  262.          ELSE
  263.             WriteF('   Warning! : \s[20]...\n', str)
  264.          ENDIF
  265.       ->ELSE
  266.         -> WriteF('lc error parsing line \d: \s[10]..\n', linenum, mem)
  267.       ->ENDIF
  268.    mem := nextLine(mem)
  269.    ENDLOOP
  270. ENDPROC
  271.  
  272. PROC nextLine(str:PTR TO CHAR)
  273.    WHILE str[] <> 10 DO str++
  274.    linenum++
  275.    str++
  276.    WHILE str[] = 10
  277.       str++
  278.       linenum++
  279.    ENDWHILE
  280. ENDPROC str
  281.  
  282.